package com.bank.Servlets;

import com.bank.dao.impl.BankCardDaoImpl;
import com.bank.dao.impl.QueryDaoImpl;
import com.bank.dao.impl.UserDaoImpl;
import com.bank.model.BankCard;
import com.bank.model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        UserDaoImpl userDao=new UserDaoImpl();
        BankCardDaoImpl bankCardDao=new BankCardDaoImpl();
        QueryDaoImpl queryDao=new QueryDaoImpl();
        //获得客户端发送的内容
        String username = request.getParameter("username");
        String identyCard = request.getParameter("identy_card");
        String bankId = request.getParameter("bank_id");
        String password = request.getParameter("password");

        BankCard bankCard=new BankCard();
        User user=new User();


        bankCard.setBank_id(bankId);
        bankCard.setCount(0);
        bankCardDao.addUser(bankCard);
        //查询所有bank表
        Integer card_id=queryDao.queryTb_Bankcard(bankId).getCard_id();

        user.setCard_id(card_id);
        user.setUsername(username);
        user.setIdenty_card(identyCard);
        user.setPassword(password);
        userDao.addUser(user);

        //将页面响应到index.jsp页面，即实现跳转
        response.sendRedirect("index.jsp");
    }
}
